#
# LaTeX.mk
# Makefile for building LaTeX project's documents.
# This makefile depends on Common.mk being included.
#

#
# Includes.
#
#include Common.mk


#
# Variables.
#

#
# Define some variables for targets.
#
doc_TARGET  = $(DOC_DIR)/Informe.pdf


#
# LaTeX source files.
#
LATEX_SOURCES = $(addprefix $(LATEX_SRC_DIR)/, apendices.tex build.tex caratula.tex conclusiones.tex desarrollo.tex discusion.tex ejecucion.tex enunciado.tex Informe.tex introduccion.tex referencias.tex resultados.tex source.tex templates.tex tp1_2_2013_1.tex tp1_2_2013_2.tex)



#
# Canned Recipes.
#

#
# Build PDF
#
define build_pdf
	@cd src/latex;						\
		pdflatex Informe.tex;				\
		cd ../../;					\
		mv src/latex/Informe.pdf doc/Informe.pdf
endef


#
# Targets.
#

#
# Define the list of .PHONY targets.
#
.PHONY: latex-clean latex-init pdf viewpdf

#
# latex-clean target.
# Deletes project generated files.
#
latex-clean:
	@rm -rf $(DOC_DIR)
	@rm -f  $(LATEX_SRC_DIR)/*.aux
	@rm -f  $(LATEX_SRC_DIR)/*.lo*
	@rm -f  $(LATEX_SRC_DIR)/*.toc

#
# Init Documentation target.
# LaTeX needs several output files as input for building
# document elements such as the table of contents. Run
# the build_pdf several times in order to produce all
# the required intermediate files.
#
latex-init: | $(DOC_DIR)
	@$(build_pdf)
	@$(build_pdf)
	@$(build_pdf)

#
# pdf target.
# Alias for the $(DOC_TARGET) target.
#
pdf: $(doc_TARGET)

#
# viewpdf target.
# Opens the project report PDF file in the default viewer.
#
viewpdf: pdf
	@$(call open) $(DOC_DIR)/Informe.pdf

#
# $(doc_TARGET) target.
# Generates the project report PDF document.
#
$(doc_TARGET): $(LATEX_SOURCES) | $(DOC_DIR)
	@echo Compiling LaTeX sources...
	@echo $(LATEX_SOURCES)
	@$(build_pdf)

